﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PrinteMaster
{
    public partial class 员工账号注册 : Form
    {
        public 员工账号注册()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            //Function.inputInt(sender, e);
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            Function.inputInt(sender, e);
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            Function.inputInt(sender, e);
        }

        private void btn注册_Click(object sender, EventArgs e)
        {
            if (textBox账号.Text.Length < 0 || textBox账号.Text.Length > 40)
            {
                MessageBox.Show("员工账号为必填字段，且长度必须小于40");
                return;
            }
            if (textBox手机.Text.Length != 11)
            {
                MessageBox.Show("手机号码为必填字段，且必须为11位");
                return;
            }
            if (textBox密码.Text.Length < 0 || textBox密码.Text.Length > 40)
            {
                MessageBox.Show("密码为必填字段，且长度必须小于40");
                return;
            }
            if (textBox短号.Text.Length != 6 && textBox短号.Text.Length != 0)
            {
                MessageBox.Show("如果你输入了短号，就必须是合法的6位短号");
                return;
            }
            if (textBox姓名.Text.Length <0 && textBox姓名.Text.Length >40)
            {
                MessageBox.Show("必须输入名字，且长度必须小于20汉字(40英文字母)");
                return;
            }
            DataBase.Error er = DataBase.getInstance().regiserManager(
                textBox账号.Text, textBox密码.Text, textBox姓名.Text,
                textBox手机.Text, textBox短号.Text);
            if (er == DataBase.Error.ok)
            {
                MessageBox.Show("注册成功!");
                Log.managerLog("为" + textBox姓名.Text + "注册账号", "老板模式", "老板模式", "老板模式");
                this.Close();
            }
            else if(er == DataBase.Error.已有该账号)
            {
                MessageBox.Show("已有该账号，账号必须唯一！");
            }
            else
            {
                MessageBox.Show("注册失败!原因=>"+er);
            }
        }
    }
}
